package descentFly.app.scrollBar
{
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	public class df_scrollBarHandle extends uif_ecomponent {
		private var _dragHandle	: Boolean;
		private var _prevMouse	: Point;
		public function df_scrollBarHandle(parent: df_scrollBar, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:Object='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
			_dragState = false;
			scrollBar.addEvent(Event.CHANGE, doChangeValue);
			addEvent(MouseEvent.MOUSE_DOWN, doDown);
			addEvent(MouseEvent.MOUSE_MOVE, doMove, stage);
			addEvent(MouseEvent.MOUSE_UP, doUp, stage);
		}
		
		protected function get scrollBar(): df_scrollBar {
			return (parent as df_scrollBar);
		}
		
		protected function doChangeValue(e: Event): void {
			_prevMouse = mousePos;
		}
/*		
		protected function update(): void {
		}*/
		
		protected function doDown(e: MouseEvent): void {
			_prevMouse 	= mousePos;
			_dragHandle = true;
		}

		protected function doMove(e: MouseEvent): void {
			if (_dragHandle) {
				scrollBar.handleDrag(mousePos.subtract(_prevMouse));
			}
		}

		protected function doUp(e: MouseEvent): void {
			_dragHandle = false;
		}
	}
}